package com.yang.doctorrecruitment.action;

import com.alibaba.fastjson.JSONObject;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yang.doctorrecruitment.dao.UserResumeDAO;
import com.yang.doctorrecruitment.dto.Skills;
import com.yang.doctorrecruitment.utils.NullChange;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class SkillsAction extends ActionSupport{
    private Skills skills;

    public String Skills(){
        int EnglishGrade=skills.getEnglishGrade();
        String SkillBooks= NullChange.NullChange(skills.getSkillBooks());
        String Training=NullChange.NullChange(skills.getTraining());
        String OtherSkills=NullChange.NullChange(skills.getOtherSkills());
        JSONObject json=new JSONObject();
        json.put("EnglishGrade",EnglishGrade);
        json.put("SkillBooks",SkillBooks);
        json.put("Training",Training);
        json.put("OtherSkills",OtherSkills);
        String jsonString =json.toJSONString();
        ActionContext ac=ActionContext.getContext();
        Map session=ac.getSession();
        String UserID= (String) session.get("UserID");

        HttpServletRequest request= (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
        boolean res= UserResumeDAO.updataSkills(jsonString,UserID);
        if(res){
            request.setAttribute("tipMessage",1);
            return SUCCESS;
        }else{
            request.setAttribute("tipMessage",2);
            return ERROR;
        }

    }
    public Skills getSkills() {
        return skills;
    }

    public void setSkills(Skills skills) {
        this.skills = skills;
    }
}
